﻿using System;
using System.Linq;
using System.Data.Entity;
using System.Collections.Generic;

namespace Optum.SN.Infra.Core.TestBase
{
    /// <summary>
    /// Provides mock data for specific types.
    /// </summary>
    internal class MockDataMap
    {
        /// <summary>
        /// Gets/sets list of entity to mock data map.
        /// </summary>
        internal List<KeyValuePair<Type, Type>> RegistrationList { get; set; }

        /// <summary>
        /// Gets mock data for specified entity.
        /// </summary>
        /// <typeparam name="T">The type for which to fetch mock data for.</typeparam>
        /// <returns>Mock data.</returns>
        internal DbSet<T> GetMockData<T>() where T : class
        {
            if (RegistrationList == null || RegistrationList.Count == 0)
                throw new Exception("Registration list is empty, at least one map item must be created to access this method.");
            var map = RegistrationList.FirstOrDefault(t => t.Key == typeof (T));
            if (map.Equals(default(KeyValuePair<Type, Type>)))
                throw new Exception(string.Format("Type {0} is not found in map list", typeof (T).FullName));
            return Activator.CreateInstance(map.Value) as DbSet<T>;
        }
    }
}